package com.example.mobile2021606144ywr0420;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

public class PartAdapter extends RecyclerView.Adapter<PartAdapter.ViewHolder>{
    int[] parts;
    String[] partname;

    public PartAdapter(int[] parts,String[]partname){
        this.parts=parts;
        this.partname=partname;
    }
    @NonNull
    @Override
    public PartAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.rv_main_part,parent,false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull PartAdapter.ViewHolder holder, int position) {
        holder.ivPart.setImageResource(parts[position]);
        holder.tvPart.setText(partname[position]);

    }

    @Override
    public int getItemCount() {
        return parts.length;
    }

    static class ViewHolder extends RecyclerView.ViewHolder{
        ImageView ivPart;
        TextView tvPart;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            this.ivPart=itemView.findViewById(R.id.iv_item_part);
            this.tvPart=itemView.findViewById(R.id.tv_item_part);
        }
    }
}
